//
//  StoreDetailBottomToolView.m
//  much
//
//  Created by weijunjie on 2019/1/8.
//  Copyright © 2019年 iOS. All rights reserved.
//

#import "StoreDetailBottomToolView.h"
#import "StoreDetailButton.h"

@interface StoreDetailBottomToolView()
@property (nonatomic, strong) StoreDetailButton *callPhoneButton;
@property (nonatomic, strong) StoreDetailButton *shoppingCarButton;
@property (nonatomic, strong) StoreDetailButton *collectionButton;
@property (nonatomic, strong) UIView *buyView;
@property (nonatomic, strong) UIButton *insertShoppingCarButton; // 加入购物车按钮
@property (nonatomic, strong) UIButton *nowBuyButton; // 立即购买按钮
@property (nonatomic, strong) UIView *topLineView;
@property (nonatomic, strong) UIImageView *remindCircleNormalView; // 消息提示
@property (nonatomic, strong) UILabel *shoppingPromptWordsLabel; // 购物车数量提示Label
@end
@implementation StoreDetailBottomToolView

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.collectionButton.hidden = NO;
        [self.insertShoppingCarButton setTitle:@"加入购物车" forState:UIControlStateNormal];
        [self.nowBuyButton setTitle:@"立即购买" forState:UIControlStateNormal];
    }
    return self;
}

/** 线视图 */
- (UIView *)topLineView {
    if (!_topLineView) {
        _topLineView = [[UIView alloc] init];
        _topLineView.backgroundColor = Color217;
        [self addSubview:_topLineView];
        [_topLineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.right.equalTo(self);
            make.height.mas_equalTo(0.5);
        }];
    }
    return _topLineView;
}
/** 客服 */
- (StoreDetailButton *)callPhoneButton {
    if (!_callPhoneButton) {
        _callPhoneButton = [[StoreDetailButton alloc] initWithIconStr:@"\uE65a" title:@"客服"];
        [_callPhoneButton setBackgroundColor:[UIColor clearColor]];
        _callPhoneButton.tag = CallPhoneToService;
        [_callPhoneButton addTarget:self action:@selector(progressShoppingCarButton:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_callPhoneButton];
        [_callPhoneButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.topLineView.mas_bottom);
            make.left.bottom.equalTo(self);
            make.width.equalTo(self.mas_height);
        }];
        
        self.remindCircleNormalView.image = [UIImage imageNamed:@"RemindCircle"];
        [_callPhoneButton addSubview:self.remindCircleNormalView];
        [self.remindCircleNormalView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.width.mas_equalTo(5);
            make.top.equalTo(self.callPhoneButton.iconLabel);
            make.right.equalTo(self.callPhoneButton.iconLabel).offset(3);
        }];
        
        UIView * line = [UIView new];
        line.backgroundColor = Color217;
        [_callPhoneButton addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.callPhoneButton.mas_right).with.offset(-0.5);
            make.top.equalTo(self.callPhoneButton);
            make.bottom.equalTo(self.callPhoneButton);
            make.width.mas_equalTo(0.5);
        }];
    }
    return _callPhoneButton;
}

/** 购物车按钮 */
- (StoreDetailButton *)shoppingCarButton {
    if (!_shoppingCarButton) {
        _shoppingCarButton = [[StoreDetailButton alloc] initWithIconStr:@"\uE6ca" title:@"购物车"];
        _shoppingCarButton.tag = GotoShoppingCarButtonType;
        [_shoppingCarButton addTarget:self action:@selector(progressShoppingCarButton:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_shoppingCarButton];
        [_shoppingCarButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.callPhoneButton.mas_right);
            make.top.bottom.equalTo(self.callPhoneButton);
            make.width.equalTo(self.mas_height);
        }];
        UIView * line = [UIView new];
        line.backgroundColor = Color217;
        [_shoppingCarButton addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.shoppingCarButton.mas_right).with.offset(-0.5);
            make.top.equalTo(self.shoppingCarButton);
            make.bottom.equalTo(self.shoppingCarButton);
            make.width.mas_equalTo(0.5);
        }];
    }
    return _shoppingCarButton;
}

/** 购物车数量提示Label */
- (UILabel *)shoppingPromptWordsLabel {
    if (!_shoppingPromptWordsLabel) {
        _shoppingPromptWordsLabel = [UILabel new];
        _shoppingPromptWordsLabel.layer.masksToBounds = YES;
        _shoppingPromptWordsLabel.layer.cornerRadius = 5.5;
        _shoppingPromptWordsLabel.textAlignment = NSTextAlignmentCenter;
        _shoppingPromptWordsLabel.textColor = [UIColor whiteColor];
        _shoppingPromptWordsLabel.backgroundColor = Color175030;
        _shoppingPromptWordsLabel.font = APPFONT(9);
        [_shoppingCarButton addSubview:_shoppingPromptWordsLabel];
        [_shoppingPromptWordsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.shoppingCarButton).with.offset(-6);
            make.top.equalTo(self.shoppingCarButton).with.offset(3);
            make.width.mas_equalTo(11);
            make.height.mas_equalTo(11);
        }];
    }
    return _shoppingPromptWordsLabel;
}

/** 收藏 */
- (StoreDetailButton *)collectionButton {
    if (!_collectionButton) {
        _collectionButton = [[StoreDetailButton alloc] initWithIconStr:@"\uE664" title:@"收藏"];
        [_collectionButton setBackgroundColor:[UIColor clearColor]];
        _collectionButton.tag = ClickGoodsCollectionButtonType;
        [_collectionButton addTarget:self action:@selector(progressShoppingCarButton:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_collectionButton];
        [_collectionButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.shoppingCarButton.mas_right);
            make.top.bottom.equalTo(self.callPhoneButton);
            make.width.equalTo(self.mas_height);
        }];
        
        UIView * line = [UIView new];
        line.backgroundColor = Color217;
        [_collectionButton addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.collectionButton.mas_right).with.offset(-0.5);
            make.top.equalTo(self.collectionButton);
            make.bottom.equalTo(self.collectionButton);
            make.width.mas_equalTo(0.5);
        }];
    }
    return _collectionButton;
}

- (UIImageView *)remindCircleNormalView {
    if (!_remindCircleNormalView) {
        _remindCircleNormalView = [[UIImageView alloc] init];
        _remindCircleNormalView.hidden = YES;
    }
    return _remindCircleNormalView;
}

- (UIView *)buyView {
    if (!_buyView) {
        _buyView = [[UIView alloc] init];
        [self addSubview:_buyView];
        [_buyView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.top.and.bottom.equalTo(self);
            make.left.equalTo(self.collectionButton.mas_right);
        }];
    }
    return _buyView;
}

/** 加入购物车按钮 */
- (UIButton *)insertShoppingCarButton {
    if (!_insertShoppingCarButton) {
        _insertShoppingCarButton = [UIButton buttonWithType:UIButtonTypeSystem];
        [_insertShoppingCarButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        _insertShoppingCarButton.tag = InsertShoppingCartButtonType;
        [_insertShoppingCarButton addTarget:self action:@selector(progressShoppingCarButton:) forControlEvents:UIControlEventTouchUpInside];
        [self.buyView addSubview:_insertShoppingCarButton];
        [_insertShoppingCarButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.and.bottom.equalTo(self.buyView);
            make.left.equalTo(self.buyView);
            make.width.equalTo(self.buyView).multipliedBy(0.5);
        }];
    }
    return _insertShoppingCarButton;
}

/** 立即购买按钮 */
- (UIButton *)nowBuyButton {
    if (!_nowBuyButton) {
        _nowBuyButton = [UIButton buttonWithType:UIButtonTypeSystem];
        [_nowBuyButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_nowBuyButton setBackgroundColor:Color175030];
        _nowBuyButton.tag = NowBuyButtonType;
        [_nowBuyButton addTarget:self action:@selector(progressShoppingCarButton:) forControlEvents:UIControlEventTouchUpInside];
        [self.buyView addSubview:_nowBuyButton];
        [_nowBuyButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.and.bottom.equalTo(self.buyView);
            make.right.equalTo(self.buyView);
            make.width.equalTo(self.buyView).multipliedBy(0.5);
        }];
    }
    return _nowBuyButton;
}

/** 进入购物车、加入购物车、立即购买按钮事件监听 */
- (void)progressShoppingCarButton:(UIButton *)sender {
    if (self.bottomViewBlock) {
        self.bottomViewBlock(sender.tag);
    }
}

@end
